<!--
/**
* @author xuyh0817
* @email xuyh0817@foxmail.com
* @date 2022-03-20 22:18
* @version 2.0.0
* @doc todo
* @website todo
* @remark  如果要分发源码，需在本文件顶部保留此文件头信息！！
*/
-->
<template>
  <!--  布局的整体插槽-->
  <x-render-extend-slot
    v-if="hasSlot(attrs.layoutName)"
    :componentFunc="getSlot(attrs.layoutName)"
    :data="attrs"
  ></x-render-extend-slot>

  <a-button v-else v-bind="attrs" @click.stop.prevent="clickHandler">
    {{ name }}
  </a-button>
</template>

<script>
import XRenderComponentMixin from '../../XRenderMixins/XRenderComponentMixin'
import XRenderExtendSlotMixin from '../../XRenderMixins/XRenderExtendSlotMixin'
import { COMPONENT_TYPE, CUSTOM_EVENT_TYPE } from '../../constants'

export default {
  name: COMPONENT_TYPE.LAYOUT_BUTTON,
  mixins: [XRenderComponentMixin, XRenderExtendSlotMixin],
  computed: {
    name: {
      get() {
        const { attrs } = this
        return attrs.name || '测试'
      }
    }
  },
  methods: {
    clickHandler() {
      const {attrs} = this
      this.$emit(CUSTOM_EVENT_TYPE.CUSTOM_EVENT, {
        type: CUSTOM_EVENT_TYPE.CHANGE,
        compType: COMPONENT_TYPE.LAYOUT_COLLAPSE,
        isLayout: true,
        layoutName: attrs.layoutName
      })
    }
  }
}
</script>

<style scoped>

</style>
